﻿namespace GameStudio.IDE.Common.Bootstrappers
{
    using System.Configuration;
    using Microsoft.Practices.ServiceLocation;
    using Microsoft.Practices.Unity;
    using Microsoft.Practices.Unity.Configuration;
    using Microsoft.Practices.Unity.ServiceLocatorAdapter;
    using GameStudio.Common.BootStrappers;

    /// <summary>
    /// Bootstrapper task to register all the configured items into the unity container
    /// </summary>
    public class IoCBootStrappertask : IBootstrapper
    {
        /// <summary>
        /// Runs this instance.
        /// </summary>
        public void Run()
        {
            // read the configuration from the unity.config 
            // http://msdn.microsoft.com/en-us/library/ff647848.aspx
            IUnityContainer container = new UnityContainer();
            var configurationSection = ConfigurationManager.GetSection("unity") as UnityConfigurationSection;
            if (configurationSection != null)
                configurationSection.Containers.Default.Configure(container);
            ////--------------------------------------------------------------------------
            ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(container));
        }
    }
}
